package com.me.util;

import com.me.pojo.PhoneCode;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;

//封装session 判断登录
public class UserContext {
    //登录的session
    private static final String LOGIN_IN_SESSON="logininfo";
    private static final String VERIFYCODE_IN_SESSION = "verifycode_in_session";

    //获取session
    private static HttpSession getSession()
    {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
    }

    //存放验证码
    public static void putVerifyCode(PhoneCode userinfo){
        getSession().setAttribute(VERIFYCODE_IN_SESSION, userinfo);
    }

    //取出session中的verifyCodeVO
    public static PhoneCode getVerifyCode(){
        PhoneCode phoneCode = (PhoneCode) getSession().getAttribute(VERIFYCODE_IN_SESSION);
        return phoneCode ;
    }
   //注销登录
    public static void closeCurrent()
    {
       getSession().removeAttribute(LOGIN_IN_SESSON);
    }

    public static void closeCode()
    {
        getSession().removeAttribute(VERIFYCODE_IN_SESSION);
    }

}

